import request from '@/utils/request'

const startUrl = '/user'

/**
 * 用户注册
 * @param username 用户名
 * @param password 密码
 * @param checkPassword 二次输入密码
 * @param university 学校
 */
export const userRegister = (username, password, checkPassword, university) =>
    request.post(startUrl + '/register', {username, password, checkPassword, university})

/**
 * 用户登录
 * @param username 用户名
 * @param password 密码
 */
export const userLogin = (username, password) =>
    request.post(startUrl + '/login', {username, password})

/**
 * 更新用户信息
 */
export const updateUserInfoApi = (userStore, password, nickname, avatarUrl, gender, phone, email, college, major) =>
    request.post(startUrl + '/update_info', {password, nickname, avatarUrl, gender, phone, email, college, major}, {
        headers: {
            'User-Token': userStore.$state.jwtEntity.jwt,
            'User-Secret-Key': userStore.$state.jwtEntity.signKeyStr
        }
    })

/**
 * 当前登录用户信息
 */
export const currentUserInfo = (userStore) =>
    request.get(startUrl + '/current', {
        headers: {
            'User-Token': userStore.$state.jwtEntity.jwt,
            'User-Secret-Key': userStore.$state.jwtEntity.signKeyStr
        }
    })

/**
 * 上传用户头像
 */
export const updateAvatar = (userStore, multipartFile) =>
    request.post(startUrl + '/avatar/update', {avatar: multipartFile}, {
        headers: {
            'Content-Type': 'multipart/form-data',
            'User-Token': userStore.$state.jwtEntity.jwt,
            'User-Secret-Key': userStore.$state.jwtEntity.signKeyStr
        }
    })

/**
 * 注销账户
 */
export const terminateUser = (userStore) =>
    request.get(startUrl + '/terminate', {
        headers: {
            'User-Token': userStore.$state.jwtEntity.jwt,
            'User-Secret-Key': userStore.$state.jwtEntity.signKeyStr
        }
    })
